using System;

namespace RTMP.SimpleClient.Extensions
{
    public static class SpanExtension
    {
        public static void WriteBigEndianValue(this Span<byte> span, uint value, int byteCount = 4)
        {
            if (span.Length < byteCount)
                throw new ArgumentException($"Span length must be at least {byteCount} bytes.");

            for (int i = 0; i < byteCount; i++)
            {
                span[i] = (byte)((value >> ((byteCount - 1 - i) * 8)) & 0xFF);
            }
        }

        public static void WriteLittleEndianValue(this Span<byte> span, uint value, int byteCount = 4)
        {
            if (span.Length < byteCount)
                throw new ArgumentException($"Span length must be at least {byteCount} bytes.");

            for (int i = 0; i < byteCount; i++)
            {
                span[i] = (byte)((value >> (i * 8)) & 0xFF);
            }
        }
    }

}